package com.cyj.dream.test.controller;

import com.cyj.dream.test.entity.UserInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Description: 用户控制器
 * @BelongsProject: DreamChardonnay
 * @BelongsPackage: com.cyj.dream.test.controller
 * @Author: ChenYongJia
 * @CreateTime: 2021-09-15 15:29
 * @Email: chen87647213@163.com
 * @Version: 1.0
 */
@Slf4j
@RestController
public class UserController {

    /**
     *
     * 通过：http://localhost:8081/api/queryUserInfo?userId=sunny
     * 拦截：http://localhost:8081/api/queryUserInfo?userId=aaa
     *
     * @param userId 用户ID
     * @return com.cyj.dream.test.entity.UserInfo
     * @date 2021/9/15 20:32
     * @author ChenYongJia
     * @version 1.0
     */
    //@DoWhiteList(key = "userId", returnJson = "{\"code\":\"1111\",\"info\":\"非白名单可访问用户拦截！\"}")
    @RequestMapping(path = "/api/queryUserInfo", method = RequestMethod.GET)
    public UserInfo queryUserInfo(@RequestParam String userId) {
        log.info("查询用户信息，userId：{}", userId);
        return new UserInfo("小佳:" + userId, 24, "河南省洛阳市涧西高新辛店镇0000-1");
    }

    /**
     * http://localhost:8081/api/queryUserInfoTwo?userId=sunny
     *
     * @param userId 用户ID
     * @return com.cyj.dream.test.entity.UserInfo
     * @date 2021/9/15 20:33
     * @author ChenYongJia
     * @version 1.0
     */
    //@DoHystrix(timeoutValue = 1000, returnJson = "{\"code\":\"1111\",\"info\":\"调用方法超过1000毫秒，熔断返回！\"}")
    @RequestMapping(path = "/api/queryUserInfoTwo", method = RequestMethod.GET)
    public UserInfo queryUserInfoTwo(@RequestParam String userId) throws InterruptedException {
        log.info("查询用户信息，userId：{}", userId);
        Thread.sleep(5000);
        return new UserInfo("小佳:" + userId, 24, "河南省洛阳市涧西高新辛店镇0000-1");
    }

}

